import Vue from "vue";
import Vuex from "vuex"
Vue.use(Vuex)

export default new Vuex.Store({
    state:{
        token: localStorage.getItem('token')?localStorage.getItem('token'):null,
        count:0,
        logininfo:{
            id:{
                type:Number
            },
            token:'',
            username:''
        }
    },
    mutations: {
        // 修改token，并将token存入localStorage
        changeLogin (state, token) {
          state.token = token;
        //   localStorage.setItem('token', user.Authorization);
        },
        add(state){
            state.count++
        },
        login(state,user){
            state.logininfo.id = user.id;
            state.logininfo.token = user.token;
            state.logininfo.username = user.username;
        }
      }

})
